#include <stdio.h>
#include <time.h>
#include "iostream.h"
#include "iomanip.h"

void test_char(char c)
{
  long old_flags = cout.flags();
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << c << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::left) << c << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::right) << c << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::internal) << c << endl;
  cout << endl;
  cout.flags(old_flags);
}

void test_string(char const* s)
{
  long old_flags = cout.flags();
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << s << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::left) << s << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::right) << s << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::adjustfield) << setiosflags(ios::internal) << s << endl;
  cout << endl;
  cout.flags(old_flags);
}

void test_int(int i, int flags)
{
  long old_flags = cout.flags();
  cout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags) << i << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags|ios::left) << i << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags|ios::right) << i << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::basefield|ios::adjustfield) << setiosflags(flags|ios::internal) << i << endl;
  cout << endl;
  cout.flags(old_flags);
}

void test_double(double d, int flags)
{
  long old_flags = cout.flags();
  cout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags) << d << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags|ios::left) << d << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags|ios::right) << d << endl;
  cout << setw(32) << setfill('_') << resetiosflags(ios::floatfield|ios::adjustfield) << setiosflags(flags|ios::internal) << d << endl;
  cout << endl;
  cout.flags(old_flags);
}

int main()
{
  ios::sync_with_stdio();

//  cout.rdbuf()->setbuf((char*)0, 4096);

  clock_t start = clock();

  char c = 'X';

  test_char(c);

  char* s = "Hello world";

  test_string(s);

  int i = 1234;

  test_int(i, 0);
  test_int(i, ios::oct);
  test_int(i, ios::dec);
  test_int(i, ios::hex);

  test_int(i, ios::uppercase);
  test_int(i, ios::uppercase|ios::oct);
  test_int(i, ios::uppercase|ios::dec);
  test_int(i, ios::uppercase|ios::hex);

  test_int(i, ios::showbase);
  test_int(i, ios::showbase|ios::oct);
  test_int(i, ios::showbase|ios::dec);
  test_int(i, ios::showbase|ios::hex);

  test_int(i, ios::uppercase|ios::showbase);
  test_int(i, ios::uppercase|ios::showbase|ios::oct);
  test_int(i, ios::uppercase|ios::showbase|ios::dec);
  test_int(i, ios::uppercase|ios::showbase|ios::hex);

  test_int(i, ios::showpos);
  test_int(i, ios::showpos|ios::oct);
  test_int(i, ios::showpos|ios::dec);
  test_int(i, ios::showpos|ios::hex);

  i = -1234;

  test_int(i, 0);
  test_int(i, ios::oct);
  test_int(i, ios::dec);
  test_int(i, ios::hex);

  test_int(i, ios::uppercase);
  test_int(i, ios::uppercase|ios::oct);
  test_int(i, ios::uppercase|ios::dec);
  test_int(i, ios::uppercase|ios::hex);

  test_int(i, ios::showbase);
  test_int(i, ios::showbase|ios::oct);
  test_int(i, ios::showbase|ios::dec);
  test_int(i, ios::showbase|ios::hex);

  test_int(i, ios::showpos);
  test_int(i, ios::showpos|ios::oct);
  test_int(i, ios::showpos|ios::dec);
  test_int(i, ios::showpos|ios::hex);

  double d = 123456789.123456789;

  test_double(d, 0);
  test_double(d, ios::fixed);
  test_double(d, ios::scientific);

  test_double(d, ios::uppercase);
  test_double(d, ios::uppercase|ios::fixed);
  test_double(d, ios::uppercase|ios::scientific);

  test_double(d, ios::showpos);
  test_double(d, ios::showpos|ios::fixed);
  test_double(d, ios::showpos|ios::scientific);

  test_double(d, ios::showpoint);
  test_double(d, ios::showpoint|ios::fixed);
  test_double(d, ios::showpoint|ios::scientific);

  d = -123456789.123456789;

  test_double(d, 0);
  test_double(d, ios::fixed);
  test_double(d, ios::scientific);

  test_double(d, ios::uppercase);
  test_double(d, ios::uppercase|ios::fixed);
  test_double(d, ios::uppercase|ios::scientific);

  test_double(d, ios::showpos);
  test_double(d, ios::showpos|ios::fixed);
  test_double(d, ios::showpos|ios::scientific);

  test_double(d, ios::showpoint);
  test_double(d, ios::showpoint|ios::fixed);
  test_double(d, ios::showpoint|ios::scientific);

  cout << "Elapsed time: " << clock()-start << endl;
}
